// MessageServiceImpl.java

package com.sateh.spaces.examples;

import com.sateh.spaces.Space;
import com.sateh.spaces.SpaceException;

public class MessageServiceImpl implements MessageService
{
    Space space;

    public void setSpace(Space space)
    {
        this.space = space;
    }

    public void sendMessage(String recipient, String content)
        throws MessageServiceException
    {
        try
        {
            space.write(new Message(recipient, content), null, Long.MAX_VALUE);
        }

        catch (SpaceException e)
        {
            throw new MessageServiceException("Cannot insert message into space: " + e.getMessage(), e);
        }
    }
}
